Page({
  data:{
    tel:"",
    tel_yanzheng:"",
    password:"",
    password2:"",
    yanzhengma:"",
    yanzheng:"获取验证码",
    on:"",
    isOutTime:false,
    yanzhengma2:""
  },
  telChange_FN:function(e){
    this.data.tel=e.detail.value;
  },
  passChange_FN:function(e){
    this.data.password=e.detail.value;
    if(this.data.password!=this.data.password2&&this.data.password2!=""){
      wx.showModal({
        "title":"提示",
        "content":"两次密码输入不一致！",
        "showCancel":false
      })
    }
  },
  pass2Change_FN:function(e){
    this.data.password2=e.detail.value;
    if(this.data.password!=this.data.password2&&this.data.password2!=""){
      wx.showModal({
        "title":"提示",
        "content":"两次密码输入不一致！",
        "showCancel":false
      })
    }
  },
  yanzhengma_FN:function(e){
    this.data.yanzhengma=e.detail.value;
  },
  zhuce_FN:function(){
    var self=this;
    console.log(self.data.tel,self.data.yanzhengma)
    if(this.data.tel==""){
      wx.showModal({
        "title":"提示",
        "content":"请输入用户名",
        "showCancel":false
      })
      return;
    }else if(this.data.password==""){
      wx.showModal({
        "title":"提示",
        "content":"请输入密码",
        "showCancel":false
      })
      return;
    }else if(this.data.password2==""){
      wx.showModal({
        "title":"提示",
        "content":"请确认密码",
        "showCancel":false
      })
      return;
    }else if(this.data.yanzhengma==""){
      wx.showModal({
        "title":"提示",
        "content":"请输验证码",
        "showCancel":false
      })
      return;
    }else if(this.data.password!=this.data.password2){
      wx.showModal({
        "title":"提示",
        "content":"两次密码输入不一致！",
        "showCancel":false
      })
      return;
    }else if(this.data.tel_yanzheng!=this.data.tel){
      wx.showModal({
        "title":"提示",
        "content":"该手机号与发送短息手机不匹配",
        "showCancel":false
      })
      return;
    }else if(this.data.yanzhengma2!=this.data.yanzhengma){
      wx.showModal({
        "title":"提示",
        "content":"短信验证码错误！",
        "showCancel":false
      })
      return;
    }
    wx.showLoading({
      mask:true
    })
    wx.request({
        url: 'https://wx.ichelaba.com/htapi/index.php/user/user/saveNewPassword',//上线的话必须是https，没有appId的本地请求貌似不受影响
        data: {
          "user_name":self.data.tel,
          "password":self.data.password
        },
        method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
        // header: {}, // 设置请求的 header
        success: function(res){
          console.log(res)
          wx.hideLoading();
          if(res.data.result){
            wx.showToast({
              "title":"修改成功",
              "mask":true
            })
            wx.reLaunch({
              url:"/pages/login/login"
            })
          }else{
            wx.showToast({
              "title":res.data.message,
              "mask":true
            })
          }
        }
      });
  },
  yanzheng_FN:function(){
    var self=this;
    if(self.data.isOutTime){
      return;
    }
    if(this.data.tel==""){
      wx.showModal({
        "title":"提示",
        "content":"请输入手机号",
        "showCancel":false
      })
      return;
    }
    this.data.tel_yanzheng=this.data.tel;
    wx.showLoading({
      "mask":true,
    })
    // wx.request({
    //   url: 'https://wx.ichelaba.com/htapi/index.php/user/user/checkMobile',//上线的话必须是https，没有appId的本地请求貌似不受影响
    //   data: {
    //     "user_name":self.data.tel
    //   },
    //   method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    //   // header: {}, // 设置请求的 header
    //   success: function(res){
    //     if(res.data.result){
          wx.request({
            url: 'https://wx.ichelaba.com/htapi/index.php/user/user/sendSmsToUser',//上线的话必须是https，没有appId的本地请求貌似不受影响
            data: {
              "user_name":self.data.tel
            },
            method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
            // header: {}, // 设置请求的 header
            success: function(res){
              wx.hideLoading();
              console.log(res);
              self.data.yanzhengma2=res.data.sms_code;
              if(res.data.result){
                wx.showToast({
                  "title":"短息发送成功",
                  "mask":true
                })
                outTime_X();
              }else{
                // wx.showToast({
                //   "title":res.data.message,
                //   "mask":true
                // })
              }
            }
          });
      //   }else{
      //     wx.hideLoading();
      //     wx.showModal({
      //       "title":"提示",
      //       "content":res.data.message,
      //       "showCancel":false
      //     })
      //   }
      // }
    // });
    function outTime_X(){
        self.data.isOutTime=true;
        var outTime=5;
        self.setData({ 
          "on":"on",
          "yanzheng":"重新发送("+outTime+")"
        })
        var timer=setInterval(function(){
          outTime--;
          self.setData({ 
            "yanzheng":"重新发送("+outTime+")"
          })
          if(outTime==0){
            outTime=5;
            self.setData({ 
              "on":"",
              "yanzheng":"获取验证码"
            });
            self.data.isOutTime=false;
            clearInterval(timer);
          }
        },1000)
    }
  }
})